import com.adobe.serialization.json.JSON;
import com.flex.core.constants.GameConstants;

import flash.events.Event;
import flash.net.URLRequest;
import flash.net.URLStream;

import mx.controls.Alert;

/**
 * @author sam
 * this is a function to do something base
 */


/**
 * read property ,init base imgList
 */
public function readProperty(url:String):void
{
	try
	{
		var loader:URLStream=new URLStream();
		loader.addEventListener(Event.COMPLETE, getHttpReq);
		var request:URLRequest=new URLRequest(url);
		loader.load(request);
	}
	catch (err:Error)
	{
		Alert.show("property connection error:" + err.message);

	}
}

/**
 * read mapInfo from txt
 */
public function getHttpReq(e:Event):void
{
	try
	{
		var us:URLStream=e.target as URLStream;
		var xmldata:String=us.readMultiByte(us.bytesAvailable, "UTF-8");
		var baseObj:Object=JSON.decode(xmldata) as Object;
		var obj:Array=baseObj["mapInfo"];
		GameConstants.MAP_WRITE_PATH=baseObj["writeMapPath"];
		for (var i:Number=0; i < obj.length; i++)
		{
			var temp:Object=obj[i];
			GameConstants.BASE_IMG_LIST.addItem(temp);
		}
	}
	catch (err:Error)
	{
		Alert.show("request error:" + err.message);
	}
}

/**
 * create base menu for game editer
 */
public function createBaseMenu():void
{
	GameConstants.BASE_ELE_MAP.puts(menu_main.id, menu_main);
	GameConstants.BASE_ELE_MAP.puts(menu_map_list.id, menu_map_list);
	GameConstants.BASE_ELE_MAP.puts(menu_info.id, menu_info);
	GameConstants.BASE_ELE_MAP.puts(menu_map_create.id, menu_map_create);
}